# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
class AttachEnum:
    IMAGE = 10     # 图片
    VIDEO = 20     # 视频
    AUDIO = 30     # 音频
    PACKAGE = 40   # 包装
    DOCUMENT = 50  # 文档

    @classmethod
    def get_code_by_msg(cls, msg: str) -> int:
        _desc = {
            "image": cls.IMAGE,
            "video": cls.VIDEO,
            "audio": cls.AUDIO,
            "package": cls.PACKAGE,
            "document": cls.DOCUMENT
        }
        return _desc.get(msg, 0)

    @classmethod
    def get_msg_by_code(cls, code: int) -> str:
        _desc = {
            cls.IMAGE: "image",
            cls.VIDEO: "video",
            cls.AUDIO: "audio",
            cls.PACKAGE: "package",
            cls.DOCUMENT: "document"
        }
        return _desc.get(code, "")

    @classmethod
    def get_type_by_ext(cls, ext: str) -> str:
        type_map = {
            'image': 'jpg,jpeg,png,gif,bmp,svg,webp,ico',
            'video': 'wmv,avi,mpg,mpeg,mov,mp4,m4v,flv,rmvb,mkv',
            'audio': 'mp3,wav,aac,ogg,flac,m4a,amr,wma,mid,midi,ape,ac3',
            'package': 'zip,rar,7z,tar,gz,bz2,tgz,tar.gz,tbz2,tar.bz2,iso,cab',
            'document': 'doc,docx,xls,xlsx,ppt,pptx,pdf,txt,html,htm,csv,md,pem'
        }
        for file_type, extensions in type_map.items():
            if ext in extensions.split(','):
                return file_type
        return ""
